package cn.jia.spring7.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by jia on 2018/4/4.
 */
@Configuration
//启用SpringMVC
@EnableWebMvc
//只扫描web下的应用
@ComponentScan("cn.jia.spring5.web")
public class WebConfig7 extends WebMvcConfigurerAdapter {
    //配置视图解析器
    //@Bean
    /*public ViewResolver viewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setPrefix(".jsp");
        //resolver.setExposeContextBeansAsAttributes(true);
        //解析jstl视图
        resolver.setViewClass(JstlView.class);
        return resolver;
    }*/

    /**
     * 配置静态资源处理
     * @param configurer
     */
/*    //@Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        //通过调用DefaultServlet-
        //HandlerConfigurer的enable()方法，我们要求DispatcherServlet将对静态资源
        //的请求转发到Servlet容器中默认的Servlet上，而不是使用DispatcherServlet本身来处理
        //此类请求。
        configurer.enable();
    }
    */

    /**
     * 配置Tiles视图解析器，定义布局
     *//*
    @Bean
    public TilesConfigurer tilesConfigurer(){
        TilesConfigurer tiles = new TilesConfigurer();
        //制定tile定义的位置
        tiles.setDefinitions("/WEB-INF*//**//*tiles.xml");
        //启用刷新功能
        tiles.setCheckRefresh(true);
        return tiles;
    }
    @Bean
    public ViewResolver viewResolver(){
        return new TilesViewResolver();
    }*/
  /*  @Bean
    public ViewResolver viewResolver(
            SpringTemplateEngine templateEngine) {
        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
        viewResolver.setTemplateEngine(templateEngine);
        return viewResolver;
    }

    @Bean
    public TemplateEngine templateEngine(TemplateResolver templateResolver) {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(templateResolver);
        return templateEngine;
    }

    @Bean
    public TemplateResolver templateResolver() {
        TemplateResolver templateResolver = new ServletContextTemplateResolver();
        templateResolver.setPrefix("/WEB-INF/templates/");
        templateResolver.setSuffix(".html");
        templateResolver.setTemplateMode("HTML5");
        return templateResolver;
    }*/
}
